#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int n,m,l,vm;
int d[N],v[N],a[N];
int p[N];
bool b[N];
bool check(int dp,int a,int v){
    return (double)sqrt((long long)v*v+(long long)2*a*dp)>(double)vm;
}
int tfind(double d){
    int l=1,r=n;
    while(l<r){
        int mid=l+r>>1;
        if((double)p[mid]<d)l=mid+1;
        else r=mid;
    }
    return l;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        int ans1=0,ans2=0;
        scanf("%d%d%d%d",&n,&m,&l,&vm);
        for(int i=1;i<=n;i++)scanf("%d%d%d",&d[i],&v[i],&a[i]);
        for(int i=1;i<=m;i++){
                scanf("%d",&p[i]);
                b[i]=1;
        }
        for(int i=1;i<=n;i++){
            if(a[i]>0&&p[m]>=d[i]&&check(p[m]-d[i],a[i],v[i]))ans1++,ans2+=b[m],b[m]=0;
            //if(a[i]<0){
            //    int t=tfind(d[i]);
            //    if(check(p[t]-d[i],a[i],v[i]))ans1++;
            //}
            if(a[i]==0&&v[i]>vm&&d[i]<=p[m])ans1++,ans2+=b[m],b[m]=0;
        }
        printf("%d%d\n",ans1,n-ans2);
    }
    return 0;
}
